local items = {
  "转换技，",
  "①你可以交给一名其他角色一张牌并视为使用或打出【闪】。",
  "②当你获得牌后，你可以视为使用一张【过河拆桥】。",
  "<font color='#E0DB2F'>①你可以交给一名其他角色一张牌并视为使用或打出【闪】。</font>",
  "<font color='#E0DB2F'>②当你获得牌后，你可以视为使用一张【过河拆桥】。</font>"
}

Fk:loadTranslationTable{
  ["plum__fuxin"] = "复信",
  [":plum__fuxin"] = "转换技，①你可以交给一名其他角色一张牌并视为使用或打出【闪】。②当你获得牌后，你可以视为使用一张【过河拆桥】。",

  [":plum__fuxin_yang"] = items[1] .. items[4] .. items[3],
  [":plum__fuxin_yin"] = items[1] .. items[2] .. items[5],

  ["#plum__fuxin-jink"] = "复信：可以视为使用或打出【闪】",
  ["#plum__fuxin-give"] = "复信：交给一名其他角色一张牌",
  ["#plum__fuxin-dismantle"] = "复信：可以视为使用一张【过河拆桥】",
  ["#plum__fuxin-target"] = "复信：视为使用一张【过河拆桥】",
}

local T = require "packages.tuntian_studio.utility"

local fuxin = fk.CreateSkill {
  name = "plum__fuxin",
  tags = {Skill.Switch},
}

--- Yang
fuxin:addEffect("viewas", {
  prompt = "#plum__fuxin-jink",
  pattern = "jink",
  card_filter = Util.FalseFunc,
  before_use = function(self, player, use)
    if player:isNude() then
      return fuxin.name
    end
    player.room:askToYiji(player, {
      cards = player:getCardIds("he"),
      targets = player.room:getOtherPlayers(player, false),
      skill_name = fuxin.name,
      min_num = 1,
      max_num = 1,
      prompt = "#plum__fuxin-give",
      cancelable = false,
    })
  end,
  view_as = function(self, player)
    local c = Fk:cloneCard(T.cardFix("jink"))
    c.skillName = fuxin.name
    return c
  end,
  enabled_at_play = function (self, player)
    return player:getSwitchSkillState(fuxin.name) == fk.SwitchYang and not player:isNude()
  end,
  enabled_at_response = function (self, player, response)
    return player:getSwitchSkillState(fuxin.name) == fk.SwitchYang and not player:isNude()
  end,
})

--- Yin
fuxin:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(fuxin.name) or player:getSwitchSkillState(fuxin.name) ~= fk.SwitchYin then return end
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Player.Hand then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(player:getCardIds("h"), info.cardId) then
            return true
          end
        end
      end
    end
  end,
   on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = T.cardFix("dismantlement"),
      skill_name = fuxin.name,
      cancelable = true,
      prompt = "#plum__fuxin-dismantle",
      skip = true,
    })
    if not use then return end
    event:setCostData(self, { data = use})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).data ---@type UseCardDataSpec
    room:useCard(use)
  end,
})

return fuxin